﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using InfoSource.Data;
using System.Web.Script.Serialization;

namespace InfoSource.Models.Views
{
	public class ManageDoNotMarketListViewModel
	{
		#region Properties ======================================================================
		private List<Do_Not_Market_List> _ZipCodes;
		public List<Do_Not_Market_List> ZipCodes
		{
			get
			{
				if (_ZipCodes == null)
					setZipCodes();

				return _ZipCodes;
			}
		}
		
		public string SerializedZipCodes 
		{ 
			get
			{				
				return new JavaScriptSerializer().Serialize(
					ZipCodes.ToDictionary(
						zip => zip.Zip.ToString()
						, zip => new { 
										City = zip.colorado_zipcode.FirstOrDefault().city
										,Lat = zip.colorado_zipcode.FirstOrDefault().Latitude
										,Long = zip.colorado_zipcode.FirstOrDefault().Longitude
									}
					)

				);
				 
			} 
		}

		public List<colorado_zipcode> RemainingZipCodes
		{
			get
			{
				InfoSourceDB db = new InfoSourceDB();
				var list = db.colorado_zipcodes;
				var zips = ZipCodes.Select(zip => zip.Zip);
				var filtered = list.Where(remaining_zip => !zips.Contains(remaining_zip.zip)).OrderBy(zip => zip.zip);
				List<colorado_zipcode> retVal = filtered.ToList();

				return retVal;
			  }
		}

        public string PrintOutputType { get; set; }

		#endregion ==============================================================================

		#region Constructor =====================================================================

		public ManageDoNotMarketListViewModel()
		{
			
		}

		#endregion ==============================================================================

		#region Methods =========================================================================
		
		private void setZipCodes()
		{
            _ZipCodes = DoNotMarketListRequests.GetDoNotMarketList().ToList();

		}

		#endregion ==============================================================================
	}
}
